package cn.bgs.service.impl;

import cn.bgs.common.R;
import cn.bgs.pojo.InvestmentAdvisory;
import cn.bgs.mapper.InvestmentAdvisoryMapper;
import cn.bgs.service.InvestmentAdvisoryService;
import cn.bgs.vo.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 招商咨询表 服务实现类
 * </p>
 *
 * @author Mr.Zhao
 * @since 2022-08-08
 */
@Service
public class InvestmentAdvisoryServiceImpl extends ServiceImpl<InvestmentAdvisoryMapper, InvestmentAdvisory> implements InvestmentAdvisoryService {

    @Autowired
    private InvestmentAdvisoryMapper investmentAdvisoryMapper;

    @Override
    public R findInvestmentAdvisory(String inAdvInfo, String inAdvCompany) {

        List<InvestmentAdvisory> investmentAdvisoryList = investmentAdvisoryMapper.findInvestmentAdvisory(inAdvInfo, inAdvCompany);

        return R.ok().data("investmentAdvisoryList",investmentAdvisoryList);
    }

    @Override
    public R findInvestmentAdvisoryId(Integer id) {

        InvestmentAdvisory investmentAdvisory = investmentAdvisoryMapper.findInvestmentAdvisoryId(id);

        return R.ok().data("investmentAdvisory",investmentAdvisory);
    }

    @Override
    public R delInvestmentAdvisory(Integer id) {

        InvestmentAdvisory investmentAdvisory = investmentAdvisoryMapper.findInvestmentAdvisoryId(id);

        investmentAdvisory.setDeleteFlag(1);

        Integer i = investmentAdvisoryMapper.updateInvestmentAdvisory(investmentAdvisory);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","删除失败");
        }

    }

    @Override
    public R addInvestmentAdvisory(InvestmentAdvisory investmentAdvisory) {

        investmentAdvisory.setInAdvNumber(RandomUtil.getSixBitRandom());

        Integer i = investmentAdvisoryMapper.addInvestmentAdvisory(investmentAdvisory);
        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","新增失败");
        }
    }

    @Override
    public R updateInvestmentAdvisory(InvestmentAdvisory investmentAdvisory) {

        Integer i = investmentAdvisoryMapper.updateInvestmentAdvisory(investmentAdvisory);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","编辑失败");
        }
    }
}
